/**
 * 功能说明:
 * 功能作者:
 * 创建日期:
 * 版权归属:每特教育|蚂蚁课堂所有 www.itmayiedu.com
 */
package com.zlp.service;

import com.zlp.utils.RedisLock;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


public class PaymentService {

	@Resource
	private RedisLock redisLock;

	public void seckill() {

		String identifier = redisLock.getLock("itmayiedu", 3L, 10L);
		if (StringUtils.isEmpty(identifier)) {
			// 获取锁失败
			System.out.println(Thread.currentThread().getName() + "线程 ,获取锁失败，原因时间超时!!!");
			return;
		}
		System.out.println(Thread.currentThread().getName() + "获取锁成功,锁id identifier:【" + identifier + "】，执行业务逻辑");
		try {
			Thread.sleep(30);
		} catch (Exception e) {

		}
		// 释放锁
		boolean releaseLock = redisLock.unLock("itmayiedu", identifier);
		if (releaseLock) {
			System.out.println(Thread.currentThread().getName() + "释放锁成功,锁id identifier:" + identifier);
		}
	}
}
